﻿using System.IO;
using Polenter.Serialization;

namespace Achievements.Serialization
{
    public static class BinarySerializer
    {
        /// <summary>
        /// Serializes the specified stream object.
        /// </summary>
        /// <param name="streamObject">The stream object.</param>
        /// <param name="obj">The obj.</param>
        public static void Serialize(Stream streamObject, object obj)
        {
            if (obj == null || streamObject == null)
                return;

            //true - binary serialization, default - xml ser.
            var serializer = new SharpSerializer(true);
            serializer.Serialize(obj, streamObject);
        }

        /// <summary>
        /// Deserializes the specified stream object.
        /// </summary>
        /// <param name="streamObject">The stream object.</param>
        /// <returns></returns>
        public static object Deserialize(Stream streamObject)
        {
            if (streamObject == null)
                return null;

            //true - binary serialization, default - xml ser.
            var serializer = new SharpSerializer(true);
            return serializer.Deserialize(streamObject);
        }
    }
}